package com.bootdo.common.task;

import com.bootdo.system.dao.DeptDao;
import com.bootdo.system.dao.WeekDao;
import com.bootdo.system.domain.WeekDO;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.util.CollectionUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 每周将班级分数置为0
 *
 * @author zhouxm
 */
@Component
public class DeptScoreJob implements Job {

    @Autowired
    private DeptDao deptDao;

    @Autowired
    private WeekDao weekDao;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Map<String,Object> map = new HashMap<String,Object>();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String weekStartDate = formatter.format(new Date());
        map.put("weekStartDate",weekStartDate);
        //查询每周周期
        List<WeekDO> list = weekDao.list(map);
        if(!CollectionUtils.isEmpty(list)) {
            //每周开始第一天将班级分数置为0
            deptDao.updateScore();
        }
    }
}
